# coding:utf-8

from rest_framework import serializers
from . import models
class CourseCategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = models.CourseCategory
        fields = ['id', 'name']


class TeacherSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Teacher
        fields = ['name', 'role_name', 'title', 'image', 'signature', 'brief']


class CourseSerializer(serializers.ModelSerializer):
    #采用子序列化的方式
    teacher = TeacherSerializer()
    class Meta:
        model = models.Course
        fields = [
            'id',
            'name',
            'course_img',
            'brief',
            'attachment_path',
            'pub_sections',
            'price',
            'students',
            'period',
            'sections',
            'course_type',
            'level_name',
            'status_name',
            'teacher', #采用子序列化的方式
            'section_list', #主页课时展示
        ]


class CourseSectionSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.CourseSection
        fields = ['name', 'orders', 'duration', 'free_trail', 'section_link', 'section_type_name']

class CourseChapterSerializer(serializers.ModelSerializer):
    #子序列化方式
    coursesections = CourseSectionSerializer(many=True)

    class Meta:
        model = models.CourseChapter
        fields = ['name', 'summary','chapter', 'coursesections']